package Druid;

import com.alibaba.druid.pool.DruidDataSourceFactory;

import javax.sql.DataSource;
import java.io.FileInputStream;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.net.URLDecoder;
import java.sql.*;
import java.util.Properties;

public class DruidSample {
    public static void main(String[] args) {
        //加载属性文件
        Properties p = new Properties();
        String propertyFile = DruidSample.class.getResource("/druid-config.properties").getPath();
        try {
            propertyFile = URLDecoder.decode(propertyFile, "UTF-8");
            p.load(new FileInputStream(propertyFile));

        } catch (Exception e) {
            e.printStackTrace();
        }
        Connection conn = null;
        //获取DataSource对象
        try {
            DataSource ds = DruidDataSourceFactory.createDataSource(p);
            conn= ds.getConnection();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }



    }
}